const news = require('../../api/news.js')
import Toast from '../../lib/vant/toast/toast';

Page({
    /**
     * 页面的初始数据
     */
    data: {
        queryList: {
            page: 1,
            count: 10
        },
        allList: []
    },
    getNewsList: function (page) {
        Toast.loading({
            mask: true,
            message: '加载中...'
        });
        let that = this
        let allList = this.data.allList
        news.getNews(page, this.data.queryList.count)
            .then(function (resp) {
                let list = resp.data.result
                console.log(list)
                for (var i in list) {
                    allList.push(list[i])
                }
                var queryList = that.data.queryList
                queryList.page = page
                that.setData({
                  queryList,allList
                })
                console.log(that.data.queryList.page)
                Toast.clear()
            })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.getNewsList(this.data.queryList.page)
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.getNewsList(this.data.queryList.page + 1)
    },

})